<?php 
/**
 * 
 * 生成js所需的信息 处理类
 * @author tanzhe
 *
 */
class js {
	private $db;
	private $url;
	
	public function __construct() {
		$this->url = new Url();
		$this->db = new Data();
	}
	
	/**
	 * 
	 * 生成美容店json
	 */
	public function getSalonJson() { 
		$allArr = array();
		//$type = $url->get('type');
		//$type = empty($type) ? 1 : $type;
		$itypeArr = array(
			1=>'hair',
			2=>'color',
			3=>'skin'
		);
		for ($iType = 1; $iType <=3; $iType ++){
			$query = $this->db->query("select `label` from appearance where `type`={$iType} order by rank asc");
			$data = $this->db->fetchAllByQuery($query);
			$salon = array();
			foreach ( $data as $i => $v ) {
				$salon[] = $v['label'];
			}
			$allArr[$itypeArr[$iType]] = $salon;
		}
		echo json_encode($allArr);
	}
	
	/**
	 * 
	 * 生成美容店json
	 */
	public function getAllSalonJson() { 
		$type = $this->url->get('type');
		$type = empty($type) ? 1 : $type;
		$query = $this->db->query("select `label`,`name`,`cost_type`,`price` from appearance order by id");
		$data = $this->db->fetchAllByQuery($query);
		$salon = array();
		foreach ( $data as $v ) {
			$salon[$v['label']] = array(
				'name'=>$v['name'],
				'cost_type'=>$v['cost_type'],
				'price'=>$v['price'],
			);
		}
		echo json_encode($salon);
	}
	
	public function getWorkplaceRequireJson() { //生成工作信息的json
		global $workRequire; 
		echo json_encode($workRequire);
	}
	
	public function getWorkJson() { //获取所有工作的信息
		$query = $this->db->query("select * from work order by id");
		$data = $this->db->fetchAllByQuery($query);
		$salon = array();
		foreach ( $data as $v ) {
			$work[$v['workplace']][] = array(
				'label'=>$v['label'],	
				'name'=>$v['name'],
				'earn'=>$v['earn'],
				'use_energy'=>$v['use_energy'],
				'work_hotness'=>$v['work_hotness'],
				'experience'=>$v['experience'],
			);
		}
		echo json_encode($work);
	}
	
	public function getShopRequireJson() { //生成服装店信息的json
		global $shopRequire; 
		echo json_encode($shopRequire);
	}
	
	public function getShopJson() { //获取商店数据
		$query = $this->db->query("select * from clothes where `shop_id`!='' order by `hotness`,`hotness_type` desc");
		$data = $this->db->fetchAllByQuery($query);
		$shop = array();
		foreach ( $data as $v ) {
			$shop[$v['shop_id']][$v['shop_type']][$v['type']][$v['label']] = array(
				'name'=>$v['name'],
				'hotness_type'=>$v['hotness_type'],
				'hotness'=>$v['hotness'],
				'cost_type'=>$v['cost_type'],
				'price'=>$v['price'],
			);
		}
		echo json_encode($shop);
	}
	public function getClothesJson() { //获取所有衣服的信息
		$query = $this->db->query("select * from clothes order by id");
		$data = $this->db->fetchAllByQuery($query);
		$clothes = array();
		foreach ( $data as $v ) {
			$clothes[$v['label']] = array(
				'name'=>$v['name'],
				'type'=>$v['type'],
				'hotness_type'=>$v['hotness_type'],
				'hotness'=>$v['hotness'],
				'cost_type'=>$v['cost_type'],
				'price'=>$v['price'],
			);
		}
		//print_r($clothes);
		echo json_encode($clothes);
	}
}
?>